// 添加对外投资
function addCompanySubmitLeft() {
    var companyName = $("#companyName").val();
    var address = $("#address").val();
    var money = $("#money").val();
    var setupTime = $("#setupTime").val();
    if ($("#companyName").val() == "" || $("#companyName").val() == undefined) {
        Feng.error("请输入名称！");
        return;
    }
    if ($("#setupTime").val() == "" || $("#setupTime").val() == undefined) {
        Feng.error("请输入成立时间！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyAddOkLeft",
        type: "post",
        data: {
            "companyName": companyName,
            "address": address,
            "money": money,
            "companyType":1,
            "setupTime": setupTime
        },
        success: function (data) {
            Feng.success(" 添加成功！");
            var html = '';
            for(var i = 0 ; i < data.length ; i++){
                html += '<div id="'+data[i].id+'" class="foreignBack_ground">'+data[i].companyName+'</div>';
            }
            $("#outboundInvestment").val("");
            $(".sharesContent_left_t").show();
            $(".sharesContent_left_h").hide();
            $(".sharesContent_left_m").hide().find(".sharesContent_branch_input").val("");
            $("#sharesContent_left_t_c").html(html);
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
}

// 添加分支机构
function addCompanySubmitRight() {
    var companyName = $("#companyNameRight").val();
    var address = $("#addressRight").val();
    var money = $("#moneyRight").val();
    var setupTime = $("#setupTimeRight").val();
    if ($("#companyNameRight").val() == "" || $("#companyNameRight").val() == undefined) {
        Feng.error("请输入名称！");
        return;
    }
    if ($("#setupTimeRight").val() == "" || $("#setupTimeRight").val() == undefined) {
        Feng.error("请输入成立时间！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyAddOkRight",
        type: "post",
        data: {
            "companyName": companyName,
            "address": address,
            "money": money,
            "companyType":2,
            "setupTime": setupTime
        },
        success: function (data) {
            Feng.success(" 添加成功！");
            var html = '';
            for(var i = 0 ; i < data.length ; i++){
                html += '<div id="'+data[i].id+'"><span class="foreignBack_block_l"></span><span>'+data[i].companyName+'</span></div>';
            }
            $(".sharesContent_right_t").show();
            $(".sharesContent_right_m").hide();
            $(".sharesContent_right_b").hide().find(".sharesContent_branch_input").val("");
            $("#sharesContent_right_t_c").html(html);
            $("#outboundBranch").val("");
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
}

// 修改对外投资
function updateCompanySubmitLeft(){
    var companyName = $("#companyName_update").val();
    var address = $("#address_update").val();
    var money = $("#money_update").val();
    var setupTime = $("#setupTime_update").val();
    var outboundInvestment = $("#outboundInvestment").val();
    if (companyName == "" || companyName == undefined) {
        Feng.error("请输入名称！");
        return;
    }
    if (setupTime == "" || setupTime == undefined) {
        Feng.error("请输入成立时间！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyEditOkLeft",
        type: "post",
        data: {
            "companyName": companyName,
            "address": address,
            "money": money,
            "setupTime": setupTime,
            "id":outboundInvestment
        },
        success: function (data) {
            Feng.success(" 修改成功！");
            var html = '';
            for(var i = 0 ; i < data.length ; i++){
                html += '<div id="'+data[i].id+'" class="foreignBack_ground">'+data[i].companyName+'</div>';
            }
            $("#outboundInvestment").val("");
            $(".sharesContent_left_t").show();
            $(".sharesContent_left_h").hide();
            $(".sharesContent_left_m").hide().find(".sharesContent_branch_input").val("");
            $("#sharesContent_left_t_c").html(html);
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
}

// 修改分支机构
function updateCompanySubmitRight(){
    var companyName = $("#companyNameRight_update").val();
    var address = $("#addressRight_update").val();
    var money = $("#moneyRight_update").val();
    var setupTime = $("#setupTimeRight_update").val();
    var outboundBranch = $("#outboundBranch").val();
    if (companyName == "" || companyName == undefined) {
        Feng.error("请输入名称！");
        return;
    }
    if (setupTime == "" || setupTime == undefined) {
        Feng.error("请输入成立时间！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyEditOkRight",
        type: "post",
        data: {
            "companyName": companyName,
            "address": address,
            "money": money,
            "setupTime": setupTime,
            "id":outboundBranch
        },
        success: function (data) {
            Feng.success(" 修改成功！");
            var html = '';
            for(var i = 0 ; i < data.length ; i++) {
                html += '<div id="' + data[i].id + '"><span class="foreignBack_block_l"></span><span>' + data[i].companyName + '</span></div>';
            }
            $(".sharesContent_right_t").show();
            $(".sharesContent_right_m").hide();
            $(".sharesContent_right_b").hide().find(".sharesContent_branch_input").val("");
            $("#sharesContent_right_t_c").html(html);
            $("#outboundBranch").val("");
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
}

// 点击修改对外投资按钮
$("#investment_modify").click(function () {
    var outboundInvestment = $("#outboundInvestment").val();
    if(outboundInvestment == "" || outboundInvestment == undefined){
        Feng.error("请选择一行！");
        return false;
    }
    $(".sharesContent_left_t").hide();
    $(".sharesContent_left_h").hide();
    $(".sharesContent_left_m").show();
    $(".sharesContent_left_t_c").find('.foreignBack_ground').css({'background':'url("https://pynnn.oss-cn-hangzhou.aliyuncs.com/an01.png") no-repeat','background-size':'100% 100%'});
    $.ajax({
        url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyEditLeft",
        type: "post",
        data: {
            "id": outboundInvestment
        },
        success: function (data) {
            $("#companyName_update").val(data.companyName);
            $("#address_update").val(data.address);
            $("#money_update").val(data.money);
            $("#setupTime_update").val(data.setupTime);
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

// 点击修改分支机构按钮
$("#branch_a_modify").click(function () {
    var outboundBranch = $("#outboundBranch").val();
    if(outboundBranch == "" || outboundBranch == undefined){
        Feng.error("请选择一行！");
        return false;
    }
    $(".sharesContent_right_t").hide();
    $(".sharesContent_right_b").hide();
    $(".sharesContent_right_m").show();
    $(".sharesContent_right_t_c").find('div').css({'color':'white'});
    $.ajax({
        url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyEditRight",
        type: "post",
        data: {
            "id": outboundBranch
        },
        success: function (data) {
            $("#companyNameRight_update").val(data.companyName);
            $("#addressRight_update").val(data.address);
            $("#moneyRight_update").val(data.money);
            $("#setupTimeRight_update").val(data.setupTime);
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

// 点击删除对外投资按钮
$("#investment_delete").click(function () {
    var outboundInvestment = $("#outboundInvestment").val();
    if(outboundInvestment == "" || outboundInvestment == undefined){
        Feng.error("请选择一行！");
        return false;
    }
    if(confirm("是否确定删除此对外投资！！！")) {
        $.ajax({
            url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyDeleteLeft",
            type: "post",
            data: {
                "id": outboundInvestment
            },
            success: function (data) {
                Feng.success(" 删除成功！");
                var html = '';
                for(var i = 0 ; i < data.length ; i++){
                    html += '<div id="'+data[i].id+'" class="foreignBack_ground">'+data[i].companyName+'</div>';
                }
                $("#outboundInvestment").val("");
                $(".sharesContent_left_t").show();
                $(".sharesContent_left_h").hide();
                $(".sharesContent_left_m").hide().find(".sharesContent_branch_input").val("");
                $("#sharesContent_left_t_c").html(html);
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
});

// 点击删除分支机构按钮
$("#branch_a_delete").click(function () {
    var outboundBranch = $("#outboundBranch").val();
    if(outboundBranch == "" || outboundBranch == undefined){
        Feng.error("请选择一行！");
        return false;
    }
    if(confirm("是否确定删除此分支机构！！！")) {
        $.ajax({
            url: Feng.ctxPath + "/sharesAreCompany/sharesAreCompanyDeleteRight",
            type: "post",
            data: {
                "id": outboundBranch
            },
            success: function (data) {
                Feng.success(" 删除成功！");
                var html = '';
                for(var i = 0 ; i < data.length ; i++){
                    html += '<div id="'+data[i].id+'"><span class="foreignBack_block_l"></span><span>'+data[i].companyName+'</span></div>';
                }
                $(".sharesContent_right_t").show();
                $(".sharesContent_right_m").hide();
                $(".sharesContent_right_b").hide().find(".sharesContent_branch_input").val("");
                $("#sharesContent_right_t_c").html(html);
                $("#outboundBranch").val("");
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
});

// 点击添加股东按钮
function shareholderSubmitLeft() {
    $(".sharesContent_left_b_h").show();
    $(".sharesContent_left_b").hide();
    // var index = layer.open({
    //     type: 2,
    //     title: '添加股东',
    //     area: ['40%', '60%'], //宽高
    //     fix: true, //不固定
    //     maxmin: true,
    //     content: Feng.ctxPath + '/sharesAreCompany/shareholderSubmitLeftAdd'
    // });
    // this.layerIndex = index;
}

// 点击取消添加股东按钮
function shareholderSubmitLeftCancel() {
    $(".sharesContent_left_b_h").hide();
    $(".sharesContent_left_b").show();
}